package com.zw.web.validation.controller;

import com.zw.web.validation.dto.SysUserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@RestController
@RequestMapping("/user")
@Validated
@Slf4j
public class SysUserController {

    @GetMapping("/info")
    public String getUserInfo(@Min(value = 1, message = "用户的ID格式不正确") @Max(value = 100000, message = "用户的ID格式不正确") @RequestParam Long userId, @Min(value = 1, message = "页码错误") int page) {
        return "普通参数校验";
    }

    @PostMapping("/register")
    public String register(@Validated({SysUserDto.UserSave.class}) @RequestBody SysUserDto sysUserDto) {
        log.info(sysUserDto.getUsername());
        return "对象参数校验";
    }

    @PostMapping("/mod")
    public String modUserInfo(@Validated({SysUserDto.UserUpdate.class}) @RequestBody SysUserDto sysUserDto) {
        log.info(sysUserDto.getUsername());
        return "对象参数校验";
    }
}

